<?php

/*
 * This file is part of PHP CS Fixer.
 *
 * (c) wangyt <wangtom365@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace App\Models;

use Illuminate\Support\Facades\DB;

class CategoryModel extends BaseModel
{
    protected $primaryKey = 'category_id';

    /**
     * Constructor.
     */
    public function __construct()
    {
        parent::__construct();
        $this->table = \Config::get('admins.tablePrefix').\Config::get('admins.tableName.categories');
    }

    /**
     * @param string $platform
     * @return mixed
     */
    public function getListByPlatform($platform = '')
    {
        $where = [];
        $where['platform'] = $platform;
        $where['status'] = 1;

        return $this->getList($where);
    }

    /**
     * @param string $module
     * @return mixed
     */
    public function getListByModule($module = '')
    {
        $where = [];
        $where['module'] = $module;
        $where['status'] = 1;

        return $this->getList($where);
    }

    /**
     * @return mixed
     */
    public function getListGroupByModule()
    {
        return self::where('status', 1)->groupBy('module_name');
    }

    /**
     * @return mixed
     */
    public function getParentCategoryList()
    {
        $where = [];
        $where['parent_id'] = 0;
        $where['status'] = 1;

        return $this->getList($where);
    }

    public function getPostCategoryList()
    {
        return $this->getListByModule('posts');
    }
}
